<?php
define('PS', PATH_SEPARATOR);
define('DS', DIRECTORY_SEPARATOR);

set_include_path(
    // this directory is where all extensions to third-party libraries are kept (so it is searched before library)
    realpath('../application/ext') . PS .
    // this directory is where all library code goes (third-party libraries)
    realpath('../library') . PS .
    // we add this here so that original include path is not overwritten
    get_include_path()
);

// autoloader loads classes on demand so we don't have to include them every time
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();

// load up fluidics functions (convenience functions)
Zend_Loader::loadFile('fluidics.php');
// load up mc2 convenience functions
Zend_Loader::loadFile('functions.php');

// get an instance of the front controller (to register plugins or what-have-you)
$front = Zend_Controller_Front::getInstance();

// Layouts are awesome... thank you zend
Zend_Layout::startMvc(array(
    'layoutPath' => '../application/views/layouts',
    'layout' => 'default',
));

// I use an extended view object here, but I probably don't need to
$view = new Q_View;
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
$viewRenderer->setViewScriptPathSpec(':controller/:action.:suffix');
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
$front->setParam('view', $view);

$config = new Zend_Config(require 'config/config.php');

// point the front controller at the controller directory
try {
    $front->run(realpath('../application/controllers'));
} catch (Zend_Controller_Dispatcher_Exception $e) {
    // @todo: only show this in debug mode
    pr($e);
}